<?
        $results = array();
        require_once('../inc/users.php');
        require_once('../inc/status.php');
        if(isset($_POST['user_ID']))
        {
                $row = $_POST;
                $results = SaveUser($row);
                if($results === true)
                {
               			header("Location: index.php?inserted=".$row['user_ID']."#Inserted");
                        die();
                }
          
        }else{
       		 if(isset($_REQUEST['id']))
                $row = GetUser($_REQUEST['id']);
             else
             	$row = blankUser();
        }
        
        $statusList = getStatus();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Details of user: <?=$row['firstName']?> <?=$row['secondName']?></title>
    <link rel="stylesheet" type="text/css" href="../inc/bootstrap.css" />
    <style type="text/css">
        .error { color: red; }
    </style>
</head>

<body>
        <div class="container">
            <div id="contents">
               <dl class="error">
                        <? foreach ($results as $key => $value): ?>
                                                <dt><?=$key?></dt>
                                                <dd><?=$value?></dd>
                                        <? endforeach; ?>
                </dl>
               
                <form class="form-horizontal" method="post" action="">
                     <div class="control-group">
                        <div class="controls">
                            <input type="hidden" name="user_ID" value="<?=$row['user_ID']?>" />
                            <select  name="status_ID" id="status_ID">
                            <option>--Select a Status--</option>
                            <? while($st = $statusList->fetch_assoc()):?>
                            <option value="<?=$st['status_ID']?>"><?=$st['statusName']?></option>
                            <? endwhile;?>
                            </select>
                        </div>
                    </div>
                    <div class=" control-group">
                        <label class="control-label" for="firstName">First Name</label>
                        <div class="controls">
                            <input type="text" name="firstName" id="firstName" value="<?=$row['firstName']?>" />
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="secondName">Last Name</label>
                        <div class="controls">
                            <input type="text" name="secondName" id="LastName" value="<?=$row['secondName']?>" />
                        </div>
                    </div>
                    <div class="control-group">
                        <div class="controls">
                        	<input class="btn btn-primary" type="submit" value="Save" />
                        	<a href="./" class="cancel-link">Cancel</a>
                        </div>
                    </div>
                </form>
           </div>
       </div>
</body>
</html>
